package com.cn.config;

import com.cn.controller.HomeController;
import com.cn.controller.LoginController;
import com.cn.controller.ProductController;
import com.cn.controller.SendCartController;
import com.cn.controller.ShoppingCartController;
import com.cn.model.Admin;
import com.cn.model.Classification;
import com.cn.model.Comment;
import com.cn.model.Commodity;
import com.cn.model.DetailedPicture;
import com.cn.model.OrderForm;
import com.cn.model.Picture;
import com.cn.model.Property;
import com.cn.model.ShoppingCart;
import com.cn.model.User;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;

public class ShoppingConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		PropKit.use("jdbc.properties");
		me.setViewType(ViewType.JSP);
		me.setDevMode(PropKit.getBoolean("devMode", false));
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", HomeController.class, "/pages");
		me.add("/shoppingCart", ShoppingCartController.class, "/pages/shoppingCart");
		me.add("/product", ProductController.class, "/pages/product");
		me.add("/login", LoginController.class, "/pages/login");
	}   
	@Override
	public void configEngine(Engine me) {
		
	}

	@Override
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl", ""),PropKit.get("username", ""), PropKit.get("password", "").trim());
		
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		//显示sql语句
		arp.setShowSql(true);
		
		arp.addMapping("admin", "id", Admin.class);
		arp.addMapping("classification", "id", Classification.class);
		arp.addMapping("comment", "id", Comment.class);
		arp.addMapping("commodity", "id", Commodity.class);
		arp.addMapping("orderform", "id", OrderForm.class);
		arp.addMapping("property", "id", Property.class);
		arp.addMapping("shoppingcart", "id", ShoppingCart.class);
		arp.addMapping("user", "id", User.class);
		me.add(c3p0Plugin);
		me.add(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configHandler(Handlers me) {
		
	}
//
//	public static void main(String[] args) {
//		JFinal.start("WebContent", 90, "/", 5);
//	}
}
